home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / compress / unzip531.zip / list.c < prev    next >
C/C++ Source or Header  |  1997-05-30  |  23KB  |  636 lines

  1. /*---------------------------------------------------------------------------
  2.  
  3.   list.c
  4.  
  5.   This file contains the non-ZipInfo-specific listing routines for UnZip.
  6.  
  7.   Contains:  list_files()
  8.              time_stamp()       [still experimental and Unix-only]
  9.              ratio()
  10.              fnprint()
  11.  
  12.   ---------------------------------------------------------------------------*/
  13.  
  14.  
  15. #define UNZIP_INTERNAL
  16. #include "unzip.h"
  17. #ifdef WINDLL
  18. #  ifdef POCKET_UNZIP
  19. #    include "wince/intrface.h"
  20. #  else
  21. #    include "windll/windll.h"
  22. #  endif
  23. #endif
  24.  
  25.  
  26. #ifdef TIME_STAMP
  27.    static int  fn_is_dir   OF((__GPRO));
  28. #endif
  29.  
  30. /* GRR 970327:  Headers*[] formerly referenced in WinGUI code; no longer? */
  31.  
  32. #ifdef OS2_EAS
  33.    char Far HeadersS[]  = " Length    EAs   ACLs    Date    Time    Name";
  34.    char Far HeadersS1[] = " ------    ---   ----    ----    ----    ----";
  35. #else
  36.    char Far HeadersS[]  = " Length    Date    Time    Name";
  37.    char Far HeadersS1[] = " ------    ----    ----    ----";
  38. #endif
  39.  
  40. static char Far CompFactorStr[] = "%c%d%%";
  41. static char Far CompFactor100[] = "100%%";
  42.  
  43. #ifndef WINDLL
  44.    char Far HeadersL[]  =
  45.      " Length  Method   Size  Ratio   Date    Time   CRC-32     Name";
  46.    char Far HeadersL1[] =
  47.      " ------  ------   ----  -----   ----    ----   ------     ----";
  48.    char Far *Headers[][2] = { {HeadersS, HeadersS1}, {HeadersL, HeadersL1} };
  49.  
  50.    static char Far CaseConversion[] = "%s (\"^\" ==> case\n%s   conversion)\n";
  51.    static char Far LongHdrStats[] =
  52.      "%7lu  %-7s%7lu %4s  %02u-%02u-%02u  %02u:%02u  %08lx  %c";
  53.    static char Far LongFileTrailer[] =
  54.      " ------          ------  ---                         \
  55.      -------\n%7lu         %7lu %4s                              %u file%s\n";
  56. #ifdef OS2_EAS
  57.    static char Far ShortHdrStats[] =
  58.      "%7lu %6lu %6lu  %02u-%02u-%02u  %02u:%02u  %c";
  59.    static char Far ShortFileTrailer[] = " ------  -----  -----        \
  60.             -------\n%7lu %6lu %6lu                    %u file%s\n";
  61.    static char Far OS2ExtAttrTrailer[] =
  62.       "%ld file%s %ld bytes of OS/2 extended attributes attached.\n";
  63.    static char Far OS2ACLTrailer[] =
  64.       "%ld file%s %ld bytes of access control lists attached.\n";
  65. #else
  66.    static char Far ShortHdrStats[] = "%7lu  %02u-%02u-%02u  %02u:%02u  %c";
  67.    static char Far ShortFileTrailer[] =
  68.      " ------                    -------\n%7lu                    %u file%s\n";
  69. #endif /* ?OS2_EAS */
  70. #endif /* ?WINDLL */
  71.  
  72.  
  73.  
  74.  
  75.  
  76. /*************************/
  77. /* Function list_files() */
  78. /*************************/
  79.  
  80. int list_files(__G)    /* return PK-type error code */
  81.     __GDEF
  82. {
  83.     char sgn, cfactorstr[10];
  84.     int do_this_file=FALSE, cfactor, error, error_in_archive=PK_COOL;
  85. #ifndef WINDLL
  86.     int longhdr=(G.vflag>1);
  87. #endif
  88.     int date_format;
  89.     unsigned methnum;
  90. #ifdef USE_EF_UT_TIME
  91.     iztimes z_utime;
  92. #endif
  93.     ush j, yr, mo, dy, hh, mm, members=0;
  94.     ulg csiz, tot_csize=0L, tot_ucsize=0L;
  95. #ifdef OS2_EAS
  96.     ulg ea_size, tot_easize=0L, tot_eafiles=0L;
  97.     ulg acl_size, tot_aclsize=0L, tot_aclfiles=0L;
  98. #endif
  99.     min_info info;
  100.     char methbuf[8];
  101.     static char dtype[]="NXFS";   /* see zi_short() */
  102.     static char Far method[NUM_METHODS+1][8] =
  103.         {"Stored", "Shrunk", "Reduce1", "Reduce2", "Reduce3", "Reduce4",
  104.          "Implode", "Token", "Defl:#", "EnhDefl", "ImplDCL", "Unk:###"};
  105.  
  106.  
  107.  
  108. /*---------------------------------------------------------------------------
  109.     Unlike extract_or_test_files(), this routine confines itself to the cen-
  110.     tral directory.  Thus its structure is somewhat simpler, since we can do
  111.     just a single loop through the entire directory, listing files as we go.
  112.  
  113.     So to start off, print the heading line and then begin main loop through
  114.     the central directory.  The results will look vaguely like the following:
  115.  
  116.   Length  Method   Size  Ratio   Date    Time   CRC-32     Name ("^" ==> case
  117.   ------  ------   ----  -----   ----    ----   ------     ----   conversion)
  118.    44004  Implode  13041  71%  11-02-89  19:34  8b4207f7   Makefile.UNIX
  119.     3438  Shrunk    2209  36%  09-15-90  14:07  a2394fd8  ^dos-file.ext
  120.   ---------------------------------------------------------------------------*/
  121.  
  122.     G.pInfo = &info;
  123.     date_format = DATE_FORMAT;
  124.  
  125. #ifndef WINDLL
  126.     if (G.qflag < 2)
  127.         if (G.L_flag)
  128.             Info(slide, 0, ((char *)slide, LoadFarString(CaseConversion),
  129.               LoadFarStringSmall(Headers[longhdr][0]),
  130.               LoadFarStringSmall2(Headers[longhdr][1])));
  131.         else
  132.             Info(slide, 0, ((char *)slide, "%s\n%s\n",
  133.                LoadFarString(Headers[longhdr][0]),
  134.                LoadFarStringSmall(Headers[longhdr][1])));
  135. #endif /* !WINDLL */
  136.  
  137.     for (j = 0; j < G.ecrec.total_entries_central_dir; ++j) {
  138.  
  139.         if (readbuf(__G__ G.sig, 4) == 0)
  140.             return PK_EOF;
  141.         if (strncmp(G.sig, G.central_hdr_sig, 4)) {  /* just to make sure */
  142.             Info(slide, 0x401, ((char *)slide, LoadFarString(CentSigMsg), j));
  143.             Info(slide, 0x401, ((char *)slide, LoadFarString(ReportMsg)));
  144.             return PK_BADERR;
  145.         }
  146.         /* process_cdir_file_hdr() sets pInfo->lcflag: */
  147.         if ((error = process_cdir_file_hdr(__G)) != PK_COOL)
  148.             return error;       /* only PK_EOF defined */
  149.  
  150.         /*
  151.          * We could DISPLAY the filename instead of storing (and possibly trun-
  152.          * cating, in the case of a very long name) and printing it, but that
  153.          * has the disadvantage of not allowing case conversion--and it's nice
  154.          * to be able to see in the listing precisely how you have to type each
  155.          * filename in order for unzip to consider it a match.  Speaking of
  156.          * which, if member names were specified on the command line, check in
  157.          * with match() to see if the current file is one of them, and make a
  158.          * note of it if it is.
  159.          */
  160.  
  161.         if ((error = do_string(__G__ G.crec.filename_length, DS_FN)) !=
  162.              PK_COOL)   /*  ^--(uses pInfo->lcflag) */
  163.         {
  164.             error_in_archive = error;
  165.             if (error > PK_WARN)   /* fatal:  can't continue */
  166.                 return error;
  167.         }
  168.         if (G.extra_field != (uch *)NULL) {
  169.             free(G.extra_field);
  170.             G.extra_field = (uch *)NULL;
  171.         }
  172.         if ((error = do_string(__G__ G.crec.extra_field_length, EXTRA_FIELD))
  173.             != 0)
  174.         {
  175.             error_in_archive = error;
  176.             if (error > PK_WARN)      /* fatal */
  177.                 return error;
  178.         }
  179.         if (!G.process_all_files) {   /* check if specified on command line */
  180.             char **pfn = G.pfnames-1;
  181.  
  182.             do_this_file = FALSE;
  183.             while (*++pfn)
  184.                 if (match(G.filename, *pfn, G.C_flag)) {
  185.                     do_this_file = TRUE;
  186.                     break;       /* found match, so stop looping */
  187.                 }
  188.             if (do_this_file) {  /* check if this is an excluded file */
  189.                 char **pxn = G.pxnames-1;
  190.  
  191.                 while (*++pxn)
  192.                     if (match(G.filename, *pxn, G.C_flag)) {
  193.                         do_this_file = FALSE;  /* ^-- ignore case in match */
  194.                         break;
  195.                     }
  196.             }
  197.         }
  198.         /*
  199.          * If current file was specified on command line, or if no names were
  200.          * specified, do the listing for this file.  Otherwise, get rid of the
  201.          * file comment and go back for the next file.
  202.          */
  203.  
  204.         if (G.process_all_files || do_this_file) {
  205.  
  206. #ifdef OS2DLL
  207.             /* this is used by UzpFileTree() to allow easy processing of lists
  208.              * of zip directory contents */
  209.             if (G.processExternally)
  210.                 if ((G.processExternally)(G.filename, &G.crec))
  211.                     break;
  212.                 else
  213.                     continue;
  214. #endif
  215. #ifdef OS2_EAS
  216.             {
  217.                 uch *ef_ptr = G.extra_field;
  218.                 int ef_size, ef_len = G.crec.extra_field_length;
  219.                 ea_size = acl_size = 0;
  220.  
  221.                 while (ef_len >= EB_HEADSIZE) {
  222.                     ef_size = makeword(&ef_ptr[EB_LEN]);
  223.                     switch (makeword(&ef_ptr[EB_ID])) {
  224.                         case EF_OS2:
  225.                             ea_size = makelong(&ef_ptr[EB_HEADSIZE]);
  226.                             break;
  227.                         case EF_ACL:
  228.                             acl_size = makelong(&ef_ptr[EB_HEADSIZE]);
  229.                             break;
  230.                     }
  231.                     ef_ptr += (ef_size + EB_HEADSIZE);
  232.                     ef_len -= (ef_size + EB_HEADSIZE);
  233.                 }
  234.             }
  235. #endif
  236. #ifdef USE_EF_UT_TIME
  237.             if (G.extra_field &&
  238.                 (ef_scan_for_izux(G.extra_field, G.crec.extra_field_length, 1,
  239.                                   &z_utime, NULL) & EB_UT_FL_MTIME))
  240.             {
  241.                 struct tm *t;
  242.  
  243.                 TIMET_TO_NATIVE(z_utime.mtime)   /* NOP unless MSC 7.0, Mac */
  244.                 t = localtime(&(z_utime.mtime));
  245.                 switch (date_format) {
  246.                     case DF_YMD:
  247.                         mo = (ush)(t->tm_year);
  248.                         dy = (ush)(t->tm_mon + 1);
  249.                         yr = (ush)(t->tm_mday);
  250.                         break;
  251.                     case DF_DMY:
  252.                         mo = (ush)(t->tm_mday);
  253.                         dy = (ush)(t->tm_mon + 1);
  254.                         yr = (ush)(t->tm_year);
  255.                         break;
  256.                     default:
  257.                         mo = (ush)(t->tm_mon + 1);
  258.                         dy = (ush)(t->tm_mday);
  259.                         yr = (ush)(t->tm_year);
  260.                 }
  261.                 hh = (ush)(t->tm_hour);
  262.                 mm = (ush)(t->tm_min);
  263.             } else
  264. #endif /* USE_EF_UT_TIME */
  265.             {
  266.                 yr = (ush)((((G.crec.last_mod_file_date >> 9) & 0x7f) + 80) %
  267.                            (unsigned)100);
  268.                 mo = (ush)((G.crec.last_mod_file_date >> 5) & 0x0f);
  269.                 dy = (ush)(G.crec.last_mod_file_date & 0x1f);
  270.  
  271.                 /* permute date so it displays according to nat'l convention */
  272.                 switch (date_format) {
  273.                     case DF_YMD:
  274.                         hh = mo; mo = yr; yr = dy; dy = hh;
  275.                         break;
  276.                     case DF_DMY:
  277.                         hh = mo; mo = dy; dy = hh;
  278.                 }
  279.  
  280.                 hh = (ush)((G.crec.last_mod_file_time >> 11) & 0x1f);
  281.                 mm = (ush)((G.crec.last_mod_file_time >> 5) & 0x3f);
  282.             }
  283.  
  284.             csiz = G.crec.csize;
  285.             if (G.crec.general_purpose_bit_flag & 1)
  286.                 csiz -= 12;   /* if encrypted, don't count encryption header */
  287.             if ((cfactor = ratio(G.crec.ucsize, csiz)) < 0) {
  288.                 sgn = '-';
  289.                 cfactor = (-cfactor + 5) / 10;
  290.             } else {
  291.                 sgn = ' ';
  292.                 cfactor = (cfactor + 5) / 10;
  293.             }
  294.             if (cfactor == 100)
  295.                 sprintf(cfactorstr, LoadFarString(CompFactor100));
  296.             else
  297.                 sprintf(cfactorstr, LoadFarString(CompFactorStr), sgn, cfactor);
  298.  
  299.             methnum = MIN(G.crec.compression_method, NUM_METHODS);
  300.             zfstrcpy(methbuf, method[methnum]);
  301.             if (methnum == DEFLATED) {
  302.                 methbuf[5] = dtype[(G.crec.general_purpose_bit_flag>>1) & 3];
  303.             } else if (methnum >= NUM_METHODS) {
  304.                 sprintf(&methbuf[4], "%03u", G.crec.compression_method);
  305.             }
  306.  
  307. #if 0       /* GRR/Euro:  add this? */
  308. #if defined(DOS_OS2_W32) || defined(UNIX)
  309.             for (p = G.filename;  *p;  ++p)
  310.                 if (!isprint(*p))
  311.                     *p = '?';  /* change non-printable chars to '?' */
  312. #endif /* DOS_OS2_W32 || UNIX */
  313. #endif /* 0 */
  314.  
  315. #ifdef WINDLL
  316.             /* send data to application for formatting and printing */
  317.             (*lpUserFunctions->SendApplicationMessage)(G.crec.ucsize, csiz,
  318.               (ush)cfactor, mo, dy, yr, hh, mm,
  319.               (char)(G.pInfo->lcflag ? '^' : ' '),
  320.               fnfilter(G.filename, slide), methbuf, G.crec.crc32,
  321.               (G.crec.general_purpose_bit_flag & 1)? 'E' : ' ');
  322. #else /* !WINDLL */
  323.             if (longhdr)
  324.                 Info(slide, 0, ((char *)slide, LoadFarString(LongHdrStats),
  325.                   G.crec.ucsize, methbuf, csiz, cfactorstr, mo, dy,
  326.                   yr, hh, mm, G.crec.crc32, (G.pInfo->lcflag? '^':' ')));
  327.             else
  328. #ifdef OS2_EAS
  329.                 Info(slide, 0, ((char *)slide, LoadFarString(ShortHdrStats),
  330.                   G.crec.ucsize, ea_size, acl_size,
  331.                   mo, dy, yr, hh, mm, (G.pInfo->lcflag? '^':' ')));
  332. #else
  333.                 Info(slide, 0, ((char *)slide, LoadFarString(ShortHdrStats),
  334.                   G.crec.ucsize,
  335.                   mo, dy, yr, hh, mm, (G.pInfo->lcflag? '^':' ')));
  336. #endif
  337.             fnprint(__G);
  338. #endif /* ?WINDLL */
  339.  
  340.             if ((error = do_string(__G__ G.crec.file_comment_length,
  341.                                    QCOND? DISPL_8 : SKIP)) != 0)
  342.             {
  343.                 error_in_archive = error;  /* might be just warning */
  344.                 if (error > PK_WARN)       /* fatal */
  345.                     return error;
  346.             }
  347.             tot_ucsize += G.crec.ucsize;
  348.             tot_csize += csiz;
  349.             ++members;
  350. #ifdef OS2_EAS
  351.             if (ea_size) {
  352.                 tot_easize += ea_size;
  353.                 ++tot_eafiles;
  354.             }
  355.             if (acl_size) {
  356.                 tot_aclsize += acl_size;
  357.                 ++tot_aclfiles;
  358.             }
  359. #endif
  360.         } else {        /* not listing this file */
  361.             SKIP_(G.crec.file_comment_length)
  362.         }
  363.     } /* end for-loop (j: files in central directory) */
  364.  
  365. /*---------------------------------------------------------------------------
  366.     Print footer line and totals (compressed size, uncompressed size, number
  367.     of members in zipfile).
  368.   ---------------------------------------------------------------------------*/
  369.  
  370.     if (G.qflag < 2) {
  371.         if ((cfactor = ratio(tot_ucsize, tot_csize)) < 0) {
  372.             sgn = '-';
  373.             cfactor = (-cfactor + 5) / 10;
  374.         } else {
  375.             sgn = ' ';
  376.             cfactor = (cfactor + 5) / 10;
  377.         }
  378.         if (cfactor == 100)
  379.             sprintf(cfactorstr, LoadFarString(CompFactor100));
  380.         else
  381.             sprintf(cfactorstr, LoadFarString(CompFactorStr), sgn, cfactor);
  382. #ifdef WINDLL
  383.         /* pass the totals back to the calling application */
  384.         lpUserFunctions->TotalSizeComp = tot_csize;
  385.         lpUserFunctions->TotalSize = tot_ucsize;
  386.         lpUserFunctions->CompFactor = cfactor;
  387.         lpUserFunctions->NumMembers = members;
  388.  
  389. #else /* !WINDLL */
  390.         if (longhdr) {
  391.             Info(slide, 0, ((char *)slide, LoadFarString(LongFileTrailer),
  392.               tot_ucsize, tot_csize, cfactorstr, members, members==1? "":"s"));
  393. #ifdef OS2_EAS
  394.             if (tot_easize || tot_aclsize)
  395.                 Info(slide, 0, ((char *)slide, "\n"));
  396.             if (tot_eafiles && tot_easize)
  397.                 Info(slide, 0, ((char *)slide, LoadFarString(OS2ExtAttrTrailer),
  398.                   tot_eafiles, tot_eafiles == 1? " has" : "s have a total of",
  399.                   tot_easize));
  400.             if (tot_aclfiles && tot_aclsize)
  401.                 Info(slide, 0, ((char *)slide, LoadFarString(OS2ACLTrailer),
  402.                   tot_aclfiles, tot_aclfiles == 1? " has" : "s have a total of",
  403.                   tot_aclsize));
  404. #endif /* OS2_EAs */
  405.         } else
  406. #ifdef OS2_EAS
  407.             Info(slide, 0, ((char *)slide, LoadFarString(ShortFileTrailer),
  408.               tot_ucsize, tot_easize, tot_aclsize, members, members == 1?
  409.               "" : "s"));
  410. #else
  411.             Info(slide, 0, ((char *)slide, LoadFarString(ShortFileTrailer),
  412.               tot_ucsize, members, members == 1? "" : "s"));
  413. #endif /* OS2_EAs */
  414. #endif /* ?WINDLL */
  415.     }
  416. /*---------------------------------------------------------------------------
  417.     Double check that we're back at the end-of-central-directory record.
  418.   ---------------------------------------------------------------------------*/
  419.  
  420.     if (readbuf(__G__ G.sig, 4) == 0)
  421.         return PK_EOF;
  422.     if (strncmp(G.sig, G.end_central_sig, 4)) {   /* just to make sure again */
  423.         Info(slide, 0x401, ((char *)slide, LoadFarString(EndSigMsg)));
  424.         error_in_archive = PK_WARN;
  425.     }
  426.     if (members == 0 && error_in_archive <= PK_WARN)
  427.         error_in_archive = PK_FIND;
  428.  
  429.     return error_in_archive;
  430.  
  431. } /* end function list_files() */
  432.  
  433.  
  434.  
  435.  
  436.  
  437. #ifdef TIMESTAMP
  438.  
  439. /************************/
  440. /* Function fn_is_dir() */
  441. /************************/
  442.  
  443. static int fn_is_dir(__G)    /* returns TRUE if G.filename is directory */
  444.     __GDEF
  445. {
  446.     extent fn_len = strlen(G.filename);
  447.     register char   endc;
  448.  
  449.     return  fn_len > 0 &&
  450.             ((endc = G.filename[fn_len-1]) == '/' ||
  451.              (G.pInfo->hostnum == FS_FAT_ && !strchr(G.filename, '/') &&
  452.               endc == '\\'));
  453. }
  454.  
  455.  
  456.  
  457.  
  458.  
  459. /*************************/
  460. /* Function time_stamp() */
  461. /*************************/
  462.  
  463. int time_stamp(__G)    /* return PK-type error code */
  464.     __GDEF
  465. {
  466.     int do_this_file=FALSE, error, error_in_archive=PK_COOL;
  467.     iztimes z_utime;
  468.     time_t last_modtime=0L;   /* assuming no zipfile data older than 1970 */
  469.     ush j, members=0;
  470.     min_info info;
  471.  
  472.  
  473. /*---------------------------------------------------------------------------
  474.     Unlike extract_or_test_files() but like list_files(), this function works
  475.     on information in the central directory alone.  Thus we have a single,
  476.     large loop through the entire directory, searching for the latest time
  477.     stamp.
  478.   ---------------------------------------------------------------------------*/
  479.  
  480.     G.pInfo = &info;
  481.  
  482.     for (j = 0; j < G.ecrec.total_entries_central_dir; ++j) {
  483.  
  484.         if (readbuf(__G__ G.sig, 4) == 0)
  485.             return PK_EOF;
  486.         if (strncmp(G.sig, G.central_hdr_sig, 4)) {  /* just to make sure */
  487.             Info(slide, 0x401, ((char *)slide, LoadFarString(CentSigMsg), j));
  488.             Info(slide, 0x401, ((char *)slide, LoadFarString(ReportMsg)));
  489.             return PK_BADERR;
  490.         }
  491.         /* process_cdir_file_hdr() sets pInfo->lcflag: */
  492.         if ((error = process_cdir_file_hdr(__G)) != PK_COOL)
  493.             return error;       /* only PK_EOF defined */
  494.         if ((error = do_string(__G__ G.crec.filename_length, DS_FN)) != PK_OK)
  495.         {        /*  ^-- (uses pInfo->lcflag) */
  496.             error_in_archive = error;
  497.             if (error > PK_WARN)   /* fatal:  can't continue */
  498.                 return error;
  499.         }
  500.         if (G.extra_field != (uch *)NULL) {
  501.             free(G.extra_field);
  502.             G.extra_field = (uch *)NULL;
  503.         }
  504.         if ((error = do_string(__G__ G.crec.extra_field_length, EXTRA_FIELD))
  505.             != 0)
  506.         {
  507.             error_in_archive = error;
  508.             if (error > PK_WARN)      /* fatal */
  509.                 return error;
  510.         }
  511.         if (!G.process_all_files) {   /* check if specified on command line */
  512.             char **pfn = G.pfnames-1;
  513.  
  514.             do_this_file = FALSE;
  515.             while (*++pfn)
  516.                 if (match(G.filename, *pfn, G.C_flag)) {
  517.                     do_this_file = TRUE;
  518.                     break;       /* found match, so stop looping */
  519.                 }
  520.             if (do_this_file) {  /* check if this is an excluded file */
  521.                 char **pxn = G.pxnames-1;
  522.  
  523.                 while (*++pxn)
  524.                     if (match(G.filename, *pxn, G.C_flag)) {
  525.                         do_this_file = FALSE;  /* ^-- ignore case in match */
  526.                         break;
  527.                     }
  528.             }
  529.         }
  530.  
  531.         /* If current file was specified on command line, or if no names were
  532.          * specified, check the time for this file.  Either way, get rid of the
  533.          * file comment and go back for the next file.
  534.          * Directory entries are always ignored, to stay compatible with both
  535.          * Zip and PKZIP.
  536.          */
  537.         if ((G.process_all_files || do_this_file) && !fn_is_dir(__G)) {
  538. #ifdef USE_EF_UT_TIME
  539.             if (G.extra_field &&
  540.                 (ef_scan_for_izux(G.extra_field, G.crec.extra_field_length, 1,
  541.                                   &z_utime, NULL) & EB_UT_FL_MTIME))
  542.             {
  543.                 if (last_modtime < z_utime.mtime)
  544.                     last_modtime = z_utime.mtime;
  545.             } else
  546. #endif /* USE_EF_UT_TIME */
  547.             {
  548.                 time_t modtime = dos_to_unix_time(G.crec.last_mod_file_date,
  549.                                                   G.crec.last_mod_file_time);
  550.  
  551.                 if (last_modtime < modtime)
  552.                     last_modtime = modtime;
  553.             }
  554.             ++members;
  555.         }
  556.         SKIP_(G.crec.file_comment_length)
  557.  
  558.     } /* end for-loop (j: files in central directory) */
  559.  
  560. /*---------------------------------------------------------------------------
  561.     Set the modification (and access) time on the zipfile, assuming we have
  562.     a modification time to set.
  563.   ---------------------------------------------------------------------------*/
  564.  
  565.     if (members > 0) {
  566.         z_utime.mtime = z_utime.atime = last_modtime;
  567.         if (utime(G.zipfn, (ztimbuf *)&z_utime))
  568.             Info(slide, 0x201, ((char *)slide,
  569.               "warning:  can't set time for %s\n", G.zipfn));
  570.     }
  571.  
  572. /*---------------------------------------------------------------------------
  573.     Double check that we're back at the end-of-central-directory record.
  574.   ---------------------------------------------------------------------------*/
  575.  
  576.     if (readbuf(__G__ G.sig, 4) == 0)
  577.         return PK_EOF;
  578.     if (strncmp(G.sig, G.end_central_sig, 4)) {   /* just to make sure again */
  579.         Info(slide, 0x401, ((char *)slide, LoadFarString(EndSigMsg)));
  580.         error_in_archive = PK_WARN;
  581.     }
  582.     if (members == 0 && error_in_archive <= PK_WARN)
  583.         error_in_archive = PK_FIND;
  584.  
  585.     return error_in_archive;
  586.  
  587. } /* end function time_stamp() */
  588.  
  589. #endif /* TIMESTAMP */
  590.  
  591.  
  592.  
  593.  
  594.  
  595. /********************/
  596. /* Function ratio() */    /* also used by ZipInfo routines */
  597. /********************/
  598.  
  599. int ratio(uc, c)
  600.     ulg uc, c;
  601. {
  602.     ulg denom;
  603.  
  604.     if (uc == 0)
  605.         return 0;
  606.     if (uc > 2000000L) {    /* risk signed overflow if multiply numerator */
  607.         denom = uc / 1000L;
  608.         return ((uc >= c) ?
  609.             (int) ((uc-c + (denom>>1)) / denom) :
  610.           -((int) ((c-uc + (denom>>1)) / denom)));
  611.     } else {             /* ^^^^^^^^ rounding */
  612.         denom = uc;
  613.         return ((uc >= c) ?
  614.             (int) ((1000L*(uc-c) + (denom>>1)) / denom) :
  615.           -((int) ((1000L*(c-uc) + (denom>>1)) / denom)));
  616.     }                            /* ^^^^^^^^ rounding */
  617. }
  618.  
  619.  
  620.  
  621.  
  622.  
  623. /************************/
  624. /*  Function fnprint()  */    /* also used by ZipInfo routines */
  625. /************************/
  626.  
  627. void fnprint(__G)    /* print filename (after filtering) and newline */
  628.     __GDEF
  629. {
  630.     char *name = fnfilter(G.filename, slide);
  631.  
  632.     (*G.message)((zvoid *)&G, (uch *)name, (ulg)strlen(name), 0);
  633.     (*G.message)((zvoid *)&G, (uch *)"\n", 1L, 0);
  634.  
  635. } /* end function fnprint() */
  636.